package com.project;
import java.text.SimpleDateFormat;
import java.util.Scanner;
import java.util.Date;
public class SmallChange {
    public static void main(String[] args) {
        boolean bool=true;
        String details="--------------零钱通明细---------";
        //定义变量
        double money=0;//收益
        double balance=0;//余额
        String note=null;//消费原因
        String exit="";
        //创建类对象
        Date date=null;
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd HH:mm");

        Scanner num=new Scanner(System.in);
        do{
            System.out.println("========零钱通菜单==========");
            System.out.println("\t\t\t1 零钱通明细");
            System.out.println("\t\t\t2 收益入账");
            System.out.println("\t\t\t3 消费");
            System.out.println("\t\t\t4 退出");
            System.out.println("请选择1~4:");
            int key=num.nextInt();
            switch(key){
                case 1:
                    System.out.println(details);
                    break;
                case 2:
                    System.out.println("收益入账");
                    money=num.nextDouble();
                    //判断金额
                    if(money<=0){
                        System.out.println("收益入账应大于0");
                        break;
                    }
                    balance+=money;
                    date =new Date();
                    details+="\n收益入账 \t+"+money+"\t"+sdf.format(date)+"\t"+balance;

                    break;
                case 3:
                    System.out.println("消费金额");
                    money=num.nextDouble();
                    //消费金额判断
                    if(money>balance||money<=0){
                        System.out.println("消费金额应在0~"+balance);
                        break;
                    }
                    System.out.println("消费原因");
                    note=num.next();
                    balance-=money;
                    date =new Date();
                    details+="\n"+note+" \t-"+money+"\t"+sdf.format(date)+"\t"+balance;
                    break;
                case 4:
                    System.out.println("退出");
                    System.out.println("确认要退出吗?  请选择y/n");
                    while(true){
                        exit=num.next();
                        if(exit.equals("y")||exit.equals("n")){
                            break;
                        }
                        else{
                            System.out.println("输入错误,请选择y/n");
                        }
                    }
                    if(exit.equals("y")){
                        bool=false;
                    }
                    break;
                default:
                    System.out.println("输入有误,请重试");
            }


        }while(bool);
    }
}
